<%@ page import="com.ws.lv.util.Res" %><%--
  Created by IntelliJ IDEA.
  User: Adminis
  Date: 2025/3/20
  Time: 09:29
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>线路附图列表</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/admin/css/bootstrap.min.css">
    <script src="${pageContext.request.contextPath}/admin/js/jquery-2.1.0.min.js"></script>
    <script src="${pageContext.request.contextPath}/admin/js/bootstrap.min.js"></script>
    <style>
        .state{
            background-color: rgba(105, 248, 116, 0.91);
            color: orangered;
        }
        b{
            color: red;
        }
        .ft{
            width: 100px;
            height: 60px;
            border-radius: 10%;
        }
    </style>
</head>
<body>

<div class="container cus-container">
    <h3 class="text-center">线路附图列表</h3>

    <div id="search-user" style="float: left; margin: 10px 0px;">
        <form class="form-inline" action="${pageContext.request.contextPath}/image/selectImages" method="post">
            <div class="form-group">
                <label for="route_name">线路名称:</label>
                <input type="text" name="route_name" value="${route_name}" class="form-control" id="route_name" placeholder="请输入关键字" style="width: 120px">
            </div>
            &nbsp;&nbsp;&nbsp;
            <div class="form-group">
                <label for="image_state">附图状态:</label>
                <select name="image_state" class="form-control" id="image_state">
                    <option value=""> -请选择状态- </option>
                    <option value="1" ${image_state == "1"? "selected" : ""}>显示</option>
                    <option value="0" ${image_state == "0"? "selected" : ""}>隐藏</option>
                </select>
            </div>
            &nbsp;&nbsp;
            <button type="submit" class="btn btn-default">查询</button>
        </form>
    </div>
    <div style="float: right;margin: 10px 0px;">
        <a class="btn btn-primary" onclick="dels()" >删除选中</a>
    </div>


    <table class="table table-bordered clearfix" id="user-list">
        <thead>
        <tr class="bg-primary">
            <th><input type="checkbox" id="firstCb"></th>
            <th>附图序号</th>
            <th>线路名称</th>
            <th>附图图片</th>
            <th>附图状态</th>
            <th>创建时间</th>
            <th>更新时间</th>
            <th>附图操作</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach items="${pageInfo.list}" var="image">
            <tr>
                <td><input type="checkbox" class="cb" value="${image.image_id}"></td>
                <td>${image.image_id}</td>
                <td>${image.route.route_name}</td>
                <td><img src="<%=Res.fuTuFileUrl%>${image.image_url}" class="ft"></td>
                <td>${image.image_state == 1 ? "显示" : "隐藏"}</td>
                <td><fmt:formatDate value="${image.image_create_time}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
                <td><fmt:formatDate value="${image.image_update_time}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
                <td>
                    <a class="btn btn-default btn-sm ${image.image_state == "1"?'state':''}" href="${pageContext.request.contextPath}/image/updateImageDisplay?image_id=${image.image_id}&route_name=${route_name}&image_state&${image_state}">显示</a>
                    <a class="btn btn-default btn-sm ${image.image_state == "0"?'state':''}" href="${pageContext.request.contextPath}/image/updateImageHide?image_id=${image.image_id}&route_name=${route_name}&image_state&${image_state}">隐藏</a>
                    <a class="btn btn-default btn-sm" href="${pageContext.request.contextPath}/image/toUpdateImage?image_id=${image.image_id}">修改</a>
                </td>
            </tr>
        </c:forEach>
        </tbody>
    </table>

    <%--前五后四--%>

    <c:if test="${pageInfo.pages>=10}">
        <c:set var="begin" value="1"></c:set>
        <c:set var="end" value="10"></c:set>
        <c:if test="${pageInfo.pageNum>5}">
            <c:set var="begin" value="${pageInfo.pageNum-4}"></c:set>
            <c:set var="end" value="${pageInfo.pageNum+5}"></c:set>
        </c:if>
        <c:if test="${pageInfo.pageNum+5>pageInfo.pages}">
            <c:set var="begin" value="${pageInfo.pages-9}"></c:set>
            <c:set var="end" value="${pageInfo.pages}"></c:set>
        </c:if>
    </c:if>

    <c:if test="${pageInfo.pages<10}">
        <c:set var="begin" value="1"></c:set>
        <c:set var="end" value="${pageInfo.pages}"></c:set>
    </c:if>

    <!-- 分页导航 -->
    <div>
        <nav style="text-align: center">
            <ul class="pagination">

                <li>
                    <a href="${pageContext.request.contextPath}/image/selectImages?currentPage=1&route_name=${route_name}&image_state=${image_state}">首页</a>
                </li>

                <li>
                    <a href="${pageContext.request.contextPath}/image/selectImages?currentPage=${pageInfo.prePage}&route_name=${route_name}&image_state=${image_state}">&laquo;</a>
                </li>

                <c:forEach begin="${begin}" end="${end}" var="page">
                    <li ${page eq pageInfo.pageNum?"class='active'":''}>
                        <a href="${pageContext.request.contextPath}/image/selectImages?currentPage=${page}&route_name=${route_name}&image_state=${image_state}">${page}</a>
                    </li>
                </c:forEach>

                <li>
                    <a href="${pageContext.request.contextPath}/image/selectImages?currentPage=${pageInfo.nextPage}&route_name=${route_name}&image_state=${image_state}">&raquo;</a>
                </li>

                <li>
                    <a href="${pageContext.request.contextPath}/image/selectImages?currentPage=${pageInfo.pages}&route_name=${route_name}&image_state=${image_state}">尾页</a>
                </li>

            </ul>
        </nav>
        <div style="float: right;">
            <span>当前第<b>${pageInfo.pageNum}</b>页 共<b>${pageInfo.pages}</b>页 共<b>${pageInfo.total}</b>条数据</span>
        </div>
    </div>



</div>


</body>
</html>

<script>
    function dels() {
        let checkeds = $("input[class='cb']:checked");
        let imageIds = "";
        for (let i = 0; i < checkeds.length; i++) {
            console.log(checkeds[i].value)
            imageIds += checkeds[i].value + ",";
        }
        if (confirm("确定删除吗？")) {
            window.location.href = "${pageContext.request.contextPath}/image/deleteImages?imageIds=" + imageIds;
        }
    }
</script>
